class Counter{
    private int count = 0;
    synchronized public  void func(){
            count++;
    }
    public int getCount(){
        return count;
    }
}
public class Demo20 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter1 = new Counter();
        Thread t1 = new Thread(() -> {
           for(int i = 0; i < 50000; i++) {
                   counter1.func();
           }
        });
        Thread t2 = new Thread(() -> {
           for(int i = 0; i < 50000; i++){
                   counter1.func();
           }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter1.getCount());
    }
}
